import axios from 'axios'

const useFetch = async (url: string): Promise<any> => {
  return await new Promise<any>((resolve, reject) => {
    axios({
      url,
      method: 'get'
    }).then(res => {
      if ( res.status === 200 ) {
        resolve(res.data)
      } else {
        reject(new Error(res.statusText))
      }
    }).catch((err) => {
      reject(new Error(err.statusText))
    })
  })
}

export { useFetch }
